package org.chuan.hisports.util;

/**
 * @Description:封装一个参数传递类
 * status：返回业务状态
 *         200：表示成功
 *         500：表示错误，信息在msg中
 *         501：bean验证错误
 *         502：拦截器拦截到用户token错误
 *         555：异常抛出错误
 */
public class JSONResult {
    //响应状态码
    private Integer status;

    //响应消息

    private String msg;

    //响应中的数据
    private Object data;
    //创建各种状态的静态方法
    public static JSONResult build(Integer status,String msg,Object data){
        return new JSONResult(status,msg,data);
    }
    public static JSONResult loginsuccess(Object data){
        return  new JSONResult(data);
    }
    public  static JSONResult registersuccess(String msg){
        return new JSONResult(200,msg,null);
    }
    public static JSONResult errorMsg(String msg){
        return new JSONResult(500,msg,null);
    }
    public static JSONResult errorMap(Object data) {
        return new JSONResult(501, "error", data);
    }

    public static JSONResult errorTokenMsg(String msg) {
        return new JSONResult(502, msg, null);
    }

    public static JSONResult errorException(String msg) {
        return new JSONResult(555, msg, null);
    }

    //构造一个全状态的函数
    public JSONResult(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }
    //构造一个只传入数据的函数
    public JSONResult(Object data){
        this.msg = "success";
        this.status = 200;
        this.data = data;
    }


    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
